/*
 * KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
 *
 * This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
 * only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
 * arose from modification of the original source, or other redistribution of this source
 * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
 */
package cn.timeoverflow.util.json;

import com.google.gson.*;

import cn.timeoverflow.bean.DeviceEvent;
import me.chanjar.weixin.common.util.json.GsonHelper;

import java.lang.reflect.Type;

/**
 */
public class DeviceEventadapter implements JsonDeserializer<DeviceEvent> {

  @Override
  public DeviceEvent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	  DeviceEvent bindEvent = new DeviceEvent();
    JsonObject accessTokenJsonObject = json.getAsJsonObject();

    if (accessTokenJsonObject.get("device_id") != null && !accessTokenJsonObject.get("device_id").isJsonNull()) {
    	bindEvent.setDevice_id(GsonHelper.getAsString(accessTokenJsonObject.get("device_id")));
    }
    
    if (accessTokenJsonObject.get("device_type") != null && !accessTokenJsonObject.get("device_type").isJsonNull()) {
    	bindEvent.setDevice_type(GsonHelper.getAsString(accessTokenJsonObject.get("device_type")));
    }

    if (accessTokenJsonObject.get("msg_id") != null && !accessTokenJsonObject.get("msg_id").isJsonNull()) {
    	bindEvent.setMsg_id(GsonHelper.getAsString(accessTokenJsonObject.get("msg_id")));
    }

    if (accessTokenJsonObject.get("msg_type") != null && !accessTokenJsonObject.get("msg_type").isJsonNull()) {
    	bindEvent.setMsg_type(GsonHelper.getAsString(accessTokenJsonObject.get("msg_type")));
    }

    if (accessTokenJsonObject.get("create_time") != null && !accessTokenJsonObject.get("create_time").isJsonNull()) {
    	bindEvent.setCreate_time(GsonHelper.getAsString(accessTokenJsonObject.get("create_time")));
    }

    if (accessTokenJsonObject.get("open_id") != null && !accessTokenJsonObject.get("open_id").isJsonNull()) {
    	bindEvent.setOpen_id(GsonHelper.getAsString(accessTokenJsonObject.get("open_id")));
    }

    if (accessTokenJsonObject.get("session_id") != null && !accessTokenJsonObject.get("session_id").isJsonNull()) {
    	bindEvent.setSession_id(GsonHelper.getAsString(accessTokenJsonObject.get("session_id")));
    }

    if (accessTokenJsonObject.get("content") != null && !accessTokenJsonObject.get("content").isJsonNull()) {
    	bindEvent.setContent(GsonHelper.getAsString(accessTokenJsonObject.get("content")));
    }

    if (accessTokenJsonObject.get("qrcode_suffix_data") != null && !accessTokenJsonObject.get("qrcode_suffix_data").isJsonNull()) {
    	bindEvent.setQrcode_suffix_data(GsonHelper.getAsString(accessTokenJsonObject.get("qrcode_suffix_data")));
    }
    return bindEvent;
  }

}
